<!-- 联系我们 -->
<template>
  <div class="contact">
    <header v-if="data.back" :style="'background: url(' + data.back + ') no-repeat 50% 50%;'">
      <span>{{ i18n.contact.contact }}</span>
    </header>
    <p class="headline">{{ i18n.contact.location }}<span></span></p>
    <img @click="open" :src="require('@/assets/1.png')" />
    <p class="headline">{{ i18n.contact.contact }}<span></span></p>
    <div class="contacts">
      <nav>
        <div>
          <img :src="require('@/assets/contact/2.png')" />
          <span>QQ</span>
          <p>{{data.qq}}</p>
        </div>
        <div>
          <img :src="require('@/assets/contact/3.png')" />
          <span>{{ i18n.contact.e_mail }}</span>
          <p>{{data.email}}</p>
        </div>
        <div>
          <img :src="require('@/assets/contact/4.png')" />
          <span>{{ i18n.contact.tel }}</span>
          <p>{{data.mobile}}</p>
        </div>
        <div @click="open">
          <img :src="require('@/assets/contact/5.png')" />
          <span>{{ i18n.contact.addresses }}</span>
          <p>{{data.address}}</p>
        </div>
      </nav>
      <main>
        <nav>
          <p>
            <span>{{ i18n.contact.compellation }}*</span>
            <input
              v-model="from.name"
              type="text"
              :placeholder="i18n.contact.compellation1"
            />
          </p>
          <p>
            <span>{{ i18n.contact.tel_user }}*</span>
            <input
              v-model="from.mobile"
              type="text"
              :placeholder="i18n.contact.tel_user1"
            />
          </p>
          <p>
            <span>{{ i18n.contact.address }}*</span>
            <input
              v-model="from.address"
              type="text"
              :placeholder="i18n.contact.address1"
            />
          </p>
        </nav>
        <textarea
          v-model="from.remarks"
          :placeholder="i18n.contact.comment"
        ></textarea>
        <button @click="contact">{{ i18n.contact.apply }}</button>
      </main>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import bus from "@/config/emit";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      data:{},
      from: {
        name: "",
        mobile: "",
        address: "",
        remarks: "",
      },
    };
  },
  //计算属性 类似于data概念
  computed: {
    i18n() {
      return this.$t("message");
    },
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getcontact(){
      this.$getRequest("/index/contact").then((res) => {
        this.data=res.data
      });
    },
    contact() {
      if (!this.from.name) {
        return this.$message({
          message: this.i18n.contact.compellation1,
          type: "warning",
        });
      }
      if (!this.from.mobile) {
        return this.$message({
          message: this.i18n.contact.tel_user1,
          type: "warning",
        });
      }
      if (!this.from.address) {
        return this.$message({
          message: this.i18n.contact.address1,
          type: "warning",
        });
      }
      this.$postRequest("/index/contact", this.from).then((res) => {
        this.$message({
          message: this.i18n.contact.submit,
          type: "success",
        });
        this.from = {
          name: "",
          mobile: "",
          address: "",
          remarks: "",
        };
      });
    },
    open() {
      window.open(
        "https://ditu.amap.com/search?id=B0IABZK99S&city=410122&geoobj=113.986665%7C34.692164%7C113.995768%7C34.696861&query_type=IDQ&query=%E9%83%91%E5%B7%9E%E8%81%94%E5%8D%8E%E7%9F%B3%E5%8C%96%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&zoom=17.5",
        "_blank"
      );
    },
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getcontact()
    bus.$on("lang", () => {
      if (this.$route.name == "/contact") {
        this.getcontact()
      }
    });
  },
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.getcontact()
  }, //如果页面有keep-alive缓存功能，激活
  deactivated() {}, //如果页面有keep-alive缓存功能，非激活
};
</script>
<style lang="less">
@keyframes translation {
  0% {
    transform: translateY(0) rotateZ(0deg);
  }
  35% {
    transform: translateY(-0.375rem) rotateZ(90deg);
  }
  70% {
    transform: translateY(0) rotateZ(180deg);
  }
  85% {
    transform: translateY(-0.1875rem) rotateZ(270deg);
  }
  100% {
    transform: translateY(0) rotateZ(360deg);
  }
}
.contact {
  background-color: #fff;
  padding: 1px 0;

  & > .contacts {
    width: 17.5rem;
    margin: 0 auto 0.875rem;

    & > main {
      width: 100%;

      & > button {
        width: 3.125rem;
        height: 0.875rem;
        background: #223ad6;
        font-size: 0.3125rem;
        color: #fff;
        font-weight: bold;
        margin-left: calc(100% - 3.125rem);
      }

      & > textarea {
        width: 100%;
        height: 2.75rem;
        margin-bottom: 0.75rem;
        padding: 0.2rem;
        box-sizing: border-box;
      }

      & > nav {
        width: 100%;
        display: flex;

        & > p {
          width: calc(100% / 3);
          display: flex;
          flex-direction: column;
          font-size: 0.375rem;

          & > input {
            width: 4.7625rem;
            height: 0.75rem;
            margin: 0.375rem 0;
            border: 1px solid #999;
            border-radius: 0.0625rem;
            padding: 0 0.2125rem;
            box-sizing: border-box;
            font-size: 0.3125rem;
          }
        }
      }
    }

    & > nav {
      display: flex;

      & > div:hover {
        & > img {
          animation: translation 0.6s linear 0s 1;
        }
      }

      & > div {
        width: 25%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 0.25rem;
        margin-bottom: 1.25rem;

        & > span {
          margin: 0.25rem;
        }

        & > img {
          width: 0.9125rem;
        }
      }
    }
  }

  & > img {
    width: 17.5rem;
    display: block;
    margin: 0 auto 0.875rem;
  }

  & > .headline {
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    position: relative;
    font-size: 0.4375rem;
    margin: 1.25rem 0;
    font-weight: bold;

    span {
      width: 1.25rem;
      height: 0.0625rem;
      border-radius: 0.0625rem;
      background: #17278d;
    }
  }

  & > header {
    width: 100%;
    height: 7.5rem;
    background-size: 100% 100% !important;
    color: #fff;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
  }
}

@media screen and (max-width: 768px) {
  @keyframes translation {
    0% {
      transform: translateY(0) rotateZ(0deg);
    }
    35% {
      transform: translateY(-2rem) rotateZ(90deg);
    }
    70% {
      transform: translateY(0) rotateZ(180deg);
    }
    85% {
      transform: translateY(-1rem) rotateZ(270deg);
    }
    100% {
      transform: translateY(0) rotateZ(360deg);
    }
  }
  .contact {
    & > .contacts {
      width: 33.5rem;
      margin: 0 auto 1rem;

      & > main {
        width: 100%;

        & > button {
          width: 10rem;
          height: 3rem;
          font-size: 1.2rem;
          border-radius: 0.5rem;
          margin-left: calc(100% - 10rem);
        }

        & > textarea {
          height: 8rem;
          margin-bottom: 1rem;
          padding: 1rem;
        }

        & > nav {
          flex-direction: column;

          & > p {
            width: 100%;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            font-size: 1rem;

            & > input {
              width: 80%;
              height: 2.5rem;
              margin: 1rem 0;
              border-radius: 0.5rem;
              padding: 0 1rem;
              font-size: 1rem;
            }
          }
        }
      }

      & > nav {
        flex-direction: column;

        & > div {
          width: 100%;
          flex-direction: row;
          align-items: center;
          justify-content: flex-start;
          font-size: 1.2rem;
          margin-bottom: 1rem;

          & > span {
            margin: 1rem;
          }

          & > img {
            width: 2rem;
          }
        }
      }
    }

    & > img {
      width: 33.5rem;
      display: block;
      margin: 0 auto 1.5rem;
    }

    & > .headline {
      font-size: 1.8rem;
      margin: 2rem 0 2rem;

      span {
        width: 4rem;
        height: 0.3rem;
        border-radius: 0.3rem;
      }
    }

    & > header {
      height: 20rem;
      background-size: auto 100% !important;
      font-size: 1.5rem;
    }
  }
}
</style>